<?php
	$triggerDIV = "";
	$HBarDIV = "";
	$VBarDIV = "";
	$StackedBarDIV = "";
	$RadarDIV = "";
	$PieDIV = "";
	?>
	<script type="text/javascript">
	
	var Season_Array = '<?php echo $_POST['season']; ?>'.split("+");
    <?php
	
	include_once('../config.php');
	LinkDataBase();
	$seasonAry = preg_split('/\+/', $_POST['season']);
	$sIndex = 0;
	foreach ($seasonAry as $season) { 
	?>
		var year = <?php echo $_POST['year']; ?>;
		var season = '<?php echo $season; ?>';
		var div;
		var url;
		<?php
		$index = 0;	
		$Array_Title = array('');
		$sIndex++;
			
		//Find sheet in droplist.
		$sql = "SELECT table_number, charttitle, charttype, keyword, contain FROM droplist, sheetreveal_first 
			WHERE droplist.id = droplist_id AND droplist.name = '".$_POST['type']."' AND 
			location_index NOT LIKE 999 GROUP BY table_number, charttitle, charttype, keyword, contain
			ORDER BY location_index";
		
		$result= mysql_query($sql);
		
		while($row = mysql_fetch_assoc($result)) {
			$table = $row['table_number'];
			$charttype = $row['charttype'];
			$Array_Title[] = $row['charttitle'];
			$index++;
		?>
			div = 'chart-<?php echo $sIndex.$index; ?>';
			href = 'href-<?php echo $index; ?>';
			
			ChartType = '#<?php echo $charttype; ?>';
			<?php
			$txt_season = '<div style="text-align:left;margin: 10px 0;"><span class="season-title">'.$season.'</span></div>';
						
			$DIV[$index] .=  $txt_season.'<div id="chart-'.$sIndex.$index.'"></div><br/><br/>';
			?>
				
			//Process keyword.
			var keyword = '';
			<?php
			if (isset($row['keyword'])) {
			?>
				keyword = '<?php echo $row['keyword']; ?>';
			<?php
			}
			?>
							
			//Process contain.
			var contain = '';
			<?php
			if (isset($row['contain'])) {
			?>
				contain = '<?php echo $row['contain']; ?>';
			<?php
			}
			?>
			
			$("#"+div+"").load('../chart/<?php echo $charttype; ?>Chart.php',
			{'year':year, 'season':season, 'tablename': '<?php echo $table; ?>', 'keyword': keyword, 
			'contain': contain});
			
			//Change href.
			$('#content-chart td#'+href+' a').attr('href','#<?php echo $table; ?>'+ChartType+'#'+keyword+'#'+contain);
		<?php
		}
		
		if ($index>3) {
		?>
			$("#overview-pager").html('<?php echo $_POST['page']; ?>');
			$(".overview-links").show();
		<?php
		}
	}
?>
	function GotoDetail(href, title) {
					
		var year = $("#year-droplist").text();
		var Array_Href = $(href).attr('href').split('#');
			
		$(".overview-links").hide();
	
		$("#content-detail").load('../chart/detail_multiple/index.php',
		{'year':year, 'season':Season_Array, 'tablename': Array_Href[1], 'charttype': Array_Href[2], 
		'keyword': Array_Href[3], 'contain': Array_Href[4], 
		'previous_title': '<a href="#" onclick="GotoBegin();" >'+title+'</a>', 'step': 1});
	}
</script>  
<div class="container2" id="content-chart">
	<div> 
        
		<?php 
		
		$loop_index = 0;
		
		$beginIndex = 1+($_POST['page']-1)*3;
		
		for ($i=$beginIndex; $i<$index+1; $i++) {
			
			if (($i==1)||(($i-1)%3==0)) {
				$ClassName = 'tablegenericleft'; 
				$CSSLocation = 'margin-left: 30px';
			}
			else {
				$ClassName = 'tablegeneric';
				$CSSLocation = 'padding: 0 20px 0 20px';
			}
			
			
			$tableHtml .= '<td><table width="300" border="1" cellspacing="0" cellpadding="0" class="'.$ClassName.'" style="'.$CSSLocation.'"><tr>
			  	<td align="center" bgcolor="#f9f9f9" color="#909090" height="40px" class="tabletop" id="href-'.($i).'">'.$Array_Title[$i].'</td></tr><tr><td align="center" class="tableimg">'.$DIV[$i].'</td></tr></table>';
			
			/**
			$tableHtml .= '<td><table width="300" border="1" cellspacing="0" cellpadding="0" class="'.$ClassName.'" style="'.$CSSLocation.'"><tr>
			  	<td align="center" bgcolor="#f9f9f9" color="#909090" height="40px" class="tabletop" id="href-'.($i).'">'.$Array_Title[$i].'
			  	<a href="#" onclick="GotoDetail(this,'.$Array_Title[$i].');">
              	<img src="../images/right-arrow.png" width="7" height="12" align="right" style="position:relative; top:3px; left:-10px; font-size:14pt; font-family:Helvetica, Arial, sans-serif">
			  	</a></td></tr><tr><td align="center" class="tableimg">'.$DIV[$i].'</td></tr></table>';
			**/
				
			$loop_index++;
			
			if ($loop_index==3)
				break;
		}
		
		echo $tableHtml; ?>
    </div>
</div>